package com.neusoft.neu24.service.impl;

import com.neusoft.neu24.Result.CommonResult;
import com.neusoft.neu24.Result.ResultCode;
import com.neusoft.neu24.dto.StatDTO;
import com.neusoft.neu24.entity.*;
import com.neusoft.neu24.mapper.StatisticsEntityMapper;
import com.neusoft.neu24.service.IStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class StatisticsServiceImpl implements IStatisticsService {
    @Autowired
    private StatisticsEntityMapper statisticsEntityMapper;

    @Override
    public void insert(StatisticsEntity statisticsEntity){
      statisticsEntityMapper.insert(statisticsEntity);
    }

    @Override
    public CommonResult<Integer> insertAll(List<StatisticsEntity> list){
        Integer res = statisticsEntityMapper.insertAll(list);
        return res == 1 ? CommonResult.success(res)
                : CommonResult.failed(ResultCode.DATA_ERROR);
    }


    @Override
    public CommonResult<StatDTO> query() {
        List<CoEntity> coEntityArrayList = statisticsEntityMapper.getLocationsWithHighCOByProvince();
        List<PMEntity> PMEntityArrayList = statisticsEntityMapper.getLocationsWithHighPMByProvince();
        List<So2Entity> So2EntityArrayList = statisticsEntityMapper.getLocationsWithHighSo2ByProvince();
        NumberEntity numberEntity = statisticsEntityMapper.getNumber();
        List<NumberofmonthEntity> numberofmonthEntities = statisticsEntityMapper.getNumberofmonth();
        List<LevelEntity> levelEntityArrayList = statisticsEntityMapper.getlevel();

        return CommonResult.success(new StatDTO(coEntityArrayList,PMEntityArrayList,
                So2EntityArrayList,numberEntity,numberofmonthEntities,
                levelEntityArrayList));
    }
}
